package com.m2team.xomnhiepanh;

import android.content.Intent;
import android.content.res.Resources;
import android.graphics.Bitmap;
import android.graphics.Bitmap.CompressFormat;
import android.graphics.Color;
import android.graphics.drawable.Drawable;
import android.net.Uri;
import android.os.AsyncTask;
import android.os.Bundle;
import android.os.Environment;
import android.support.v7.app.ActionBarActivity;
import android.util.Log;
import android.util.TypedValue;
import android.view.ext.SatelliteMenu;
import android.view.ext.SatelliteMenu.SateliteClickedListener;
import android.view.ext.SatelliteMenuItem;
import android.widget.ImageView;
import android.widget.TextView;
import android.widget.Toast;
import com.makeramen.RoundedImageView;
import com.ortiz.touch.TouchImageView;
import com.squareup.picasso.Picasso;
import com.squareup.picasso.Picasso.LoadedFrom;
import com.squareup.picasso.RequestCreator;
import com.squareup.picasso.Target;
import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import org.jsoup.Connection;
import org.jsoup.Jsoup;
import org.jsoup.nodes.Document;
import org.jsoup.nodes.Element;
import org.jsoup.select.Elements;

public class ImageActivity
  extends ActionBarActivity
{
  private static final int DOWNLOAD_BUTTON_ID = 2;
  private static final int SHARE_BUTTON_ID = 1;
  private static final int VIEW_DETAIL_BUTTON_ID = 3;
  TextView apertureTextView;
  TextView authorNameTextView;
  TextView authorUsernameView;
  ImageView avatarImg;
  RoundedImageView avatarRoundAuthor;
  TextView favoriteView;
  TextView fstopTextView;
  TextView isoTextView;
  TouchImageView photoFullImgView;
  private Target target = new Target()
  {
    public void onBitmapFailed(Drawable paramAnonymousDrawable)
    {
      Toast.makeText(ImageActivity.this, "Download failed", 0).show();
    }
    
    public void onBitmapLoaded(final Bitmap paramAnonymousBitmap, Picasso.LoadedFrom paramAnonymousLoadedFrom)
    {
      new Thread(new Runnable()
      {
        public void run()
        {
          File localFile = new File(Environment.getExternalStorageDirectory().getPath() + "/" + "XomNhiepAnh" + "/" + ImageActivity.this.title + ".jpg");
          try
          {
            localFile.createNewFile();
            FileOutputStream localFileOutputStream = new FileOutputStream(localFile);
            paramAnonymousBitmap.compress(Bitmap.CompressFormat.JPEG, 100, localFileOutputStream);
            localFileOutputStream.close();
            return;
          }
          catch (Exception localException)
          {
            localException.printStackTrace();
          }
        }
      }).start();
    }
    
    public void onPrepareLoad(Drawable paramAnonymousDrawable)
    {
      if (paramAnonymousDrawable != null) {
        Toast.makeText(ImageActivity.this, "Download starting...", 0).show();
      }
    }
  };
  TextView timeAddedView;
  String title = "Image";
  TextView titleView;
  String uriString = "";
  TextView viewTextView;
  
  private void downloadImage(Uri paramUri)
  {
    Picasso.with(this).load(paramUri).into(this.target);
  }
  
  private void initActionButton()
  {
    SatelliteMenu localSatelliteMenu = (SatelliteMenu)findViewById(2131099722);
    localSatelliteMenu.setSatelliteDistance((int)TypedValue.applyDimension(1, 100.0F, getResources().getDisplayMetrics()));
    localSatelliteMenu.setExpandDuration(500);
    localSatelliteMenu.setCloseItemsOnClick(true);
    localSatelliteMenu.setTotalSpacingDegree(100.0F);
    ArrayList localArrayList = new ArrayList();
    localArrayList.add(new SatelliteMenuItem(3, 2130837618));
    localArrayList.add(new SatelliteMenuItem(2, 2130837608));
    localArrayList.add(new SatelliteMenuItem(1, 2130837627));
    localSatelliteMenu.addItems(localArrayList);
    localSatelliteMenu.setOnItemClickedListener(new SatelliteMenu.SateliteClickedListener()
    {
      public void eventOccured(int paramAnonymousInt)
      {
        Log.i("sat", "Clicked on " + paramAnonymousInt);
        if (paramAnonymousInt == 1)
        {
          Intent localIntent1 = new Intent("android.intent.action.SEND");
          localIntent1.addFlags(524288);
          localIntent1.setType("image/*");
          ImageActivity.this.startActivity(localIntent1);
        }
        do
        {
          do
          {
            return;
            if (paramAnonymousInt != 2) {
              break;
            }
          } while ((ImageActivity.this.uriString == null) || (ImageActivity.this.uriString.trim().length() <= 0));
          ImageActivity.this.downloadImage(Uri.parse(ImageActivity.this.uriString));
          return;
        } while (paramAnonymousInt != 3);
        Intent localIntent2 = new Intent(ImageActivity.this, ViewExifDetailActivity.class);
        ImageActivity.this.startActivity(localIntent2);
      }
    });
  }
  
  private void initView()
  {
    this.photoFullImgView = ((TouchImageView)findViewById(2131099721));
    this.titleView = ((TextView)findViewById(2131099742));
    this.timeAddedView = ((TextView)findViewById(2131099743));
    this.viewTextView = ((TextView)findViewById(2131099734));
    this.favoriteView = ((TextView)findViewById(2131099735));
    this.isoTextView = ((TextView)findViewById(2131099739));
    this.apertureTextView = ((TextView)findViewById(2131099740));
    this.fstopTextView = ((TextView)findViewById(2131099741));
    this.authorUsernameView = ((TextView)findViewById(2131099746));
    this.authorNameTextView = ((TextView)findViewById(2131099745));
    this.avatarRoundAuthor = ((RoundedImageView)findViewById(2131099744));
  }
  
  protected void onCreate(Bundle paramBundle)
  {
    super.onCreate(paramBundle);
    requestWindowFeature(1);
    setContentView(2130903064);
    initActionButton();
    initView();
    Bundle localBundle = getIntent().getExtras();
    this.uriString = localBundle.getString("url");
    if ((this.uriString != null) && (this.uriString.trim().length() > 0)) {
      Picasso.with(this).load(this.uriString).centerInside().resize(2000, 2000).placeholder(2130837591).error(2130837612).into(this.photoFullImgView);
    }
    this.title = localBundle.getString("title");
    if ((this.title != null) && (this.title.trim().length() > 0)) {
      this.titleView.setText(this.title);
    }
    String str1 = localBundle.getString("author");
    if ((str1 != null) && (str1.trim().length() > 0)) {
      this.authorUsernameView.setText(str1);
    }
    String str2 = localBundle.getString("href");
    if ((str2 != null) && (str2.trim().length() > 0))
    {
      ParseImageContentURL localParseImageContentURL = new ParseImageContentURL();
      String[] arrayOfString = new String[1];
      arrayOfString[0] = ("http://xomnhiepanh.com" + str2);
      localParseImageContentURL.execute(arrayOfString);
    }
  }
  
  class ParseAuthorURL
    extends AsyncTask<String, Void, Void>
  {
    HashMap<String, String> mapAuthor = new HashMap();
    
    ParseAuthorURL() {}
    
    protected Void doInBackground(String... paramVarArgs)
    {
      try
      {
        Document localDocument = Jsoup.connect(paramVarArgs[0]).get();
        if (localDocument != null)
        {
          Elements localElements = localDocument.select(".genTitle");
          if ((localElements != null) && (localElements.size() > 0))
          {
            String str = localElements.get(0).text();
            this.mapAuthor.put("authorName", str);
          }
        }
      }
      catch (IOException localIOException)
      {
        for (;;)
        {
          localIOException.printStackTrace();
        }
      }
      return null;
    }
    
    protected void onPostExecute(Void paramVoid)
    {
      super.onPostExecute(paramVoid);
      if ((this.mapAuthor.size() > 0) && (this.mapAuthor.get("authorName") != null)) {
        ImageActivity.this.authorNameTextView.setText((CharSequence)this.mapAuthor.get("authorName"));
      }
    }
    
    protected void onPreExecute()
    {
      super.onPreExecute();
      ImageActivity.this.authorNameTextView.setText("");
    }
  }
  
  class ParseImageContentURL
    extends AsyncTask<String, Void, Void>
  {
    String author;
    String avatarAuthorURL;
    String colorHex;
    String comment;
    Element element;
    String exif;
    Elements exifs;
    String favorite;
    StringBuilder linkBuilder = new StringBuilder();
    HashMap<String, String> mapExif = new HashMap();
    String profileAuthorURL;
    String styleAuthor;
    String time;
    String view;
    
    ParseImageContentURL() {}
    
    private String processAddTime(String paramString)
    {
      String str = "";
      if ((paramString != null) && (paramString.trim().length() > 0))
      {
        int i = paramString.lastIndexOf(" ");
        if (i >= 0)
        {
          str = paramString.substring(i);
          if ((str != null) && (str.trim().length() > 0)) {
            return str.trim();
          }
        }
      }
      return str;
    }
    
    private void processExif(Elements paramElements)
    {
      int i;
      if (paramElements != null)
      {
        i = 0;
        if (i < paramElements.size()) {}
      }
      else
      {
        return;
      }
      this.element = paramElements.get(i);
      String str2;
      if (this.element != null)
      {
        String str1 = this.element.text();
        if ((str1 != null) && (str1.trim().length() > 0))
        {
          int j = str1.indexOf(" ");
          if (j > 0)
          {
            str2 = str1.substring(0, j);
            String str3 = str1.substring(j);
            if ((str2 != null) && (str2.trim().length() > 0))
            {
              if ((str3 == null) || (str3.trim().length() <= 0)) {
                break label139;
              }
              this.mapExif.put(str2.toLowerCase(), str3.trim());
            }
          }
        }
      }
      for (;;)
      {
        i++;
        break;
        label139:
        this.mapExif.put(str2.toLowerCase(), "");
      }
    }
    
    protected Void doInBackground(String... paramVarArgs)
    {
      try
      {
        Document localDocument = Jsoup.connect(paramVarArgs[0]).get();
        if (localDocument != null)
        {
          this.view = localDocument.select("span#viewCount").html();
          this.comment = localDocument.select("span#commentCount").html();
          this.favorite = localDocument.select("span#faveCount").html();
          this.time = localDocument.select("div.takenTime").html();
          this.exifs = localDocument.select("#tborder tr");
          processExif(this.exifs);
          Elements localElements = localDocument.select(".userInfo .avatar a[href]");
          this.avatarAuthorURL = localElements.select("img").attr("src");
          this.profileAuthorURL = localElements.select("a").attr("href");
          this.styleAuthor = localDocument.select(".userInfo .fl span").select("span").attr("style");
          if ((this.styleAuthor != null) && (this.styleAuthor.trim().length() > 0))
          {
            int i = this.styleAuthor.indexOf("color:");
            if (i >= 0) {
              this.colorHex = this.styleAuthor.substring(i + 6, i + 13);
            }
          }
        }
      }
      catch (Throwable localThrowable)
      {
        for (;;)
        {
          localThrowable.printStackTrace();
        }
      }
      return null;
    }
    
    protected void onPostExecute(Void paramVoid)
    {
      super.onPostExecute(paramVoid);
      ImageActivity.this.timeAddedView.setText(processAddTime(this.time));
      ImageActivity.this.viewTextView.setText(this.view);
      ImageActivity.this.favoriteView.setText(this.favorite);
      if (this.mapExif.size() > 0)
      {
        if (this.mapExif.containsKey("Iso".toLowerCase()))
        {
          String str3 = (String)this.mapExif.get("Iso".toLowerCase());
          if (str3 != null) {
            ImageActivity.this.isoTextView.setText(str3);
          }
        }
        if (this.mapExif.containsKey("ExposureTime".toLowerCase()))
        {
          String str2 = (String)this.mapExif.get("ExposureTime".toLowerCase());
          if (str2 != null) {
            ImageActivity.this.apertureTextView.setText(str2);
          }
        }
        if (this.mapExif.containsKey("FNumber".toLowerCase()))
        {
          String str1 = (String)this.mapExif.get("FNumber".toLowerCase());
          if (str1 != null) {
            ImageActivity.this.fstopTextView.setText(str1);
          }
        }
      }
      if ((this.avatarAuthorURL != null) && (this.avatarAuthorURL.trim().length() > 0)) {
        Picasso.with(ImageActivity.this).load(this.avatarAuthorURL).error(2130837612).into(ImageActivity.this.avatarRoundAuthor);
      }
      if ((this.profileAuthorURL != null) && (this.profileAuthorURL.trim().length() > 0))
      {
        ImageActivity.ParseAuthorURL localParseAuthorURL = new ImageActivity.ParseAuthorURL(ImageActivity.this);
        String[] arrayOfString = new String[1];
        arrayOfString[0] = ("http://xomnhiepanh.com" + this.profileAuthorURL);
        localParseAuthorURL.execute(arrayOfString);
      }
      if ((this.colorHex != null) && (this.colorHex.trim().length() > 0)) {
        ImageActivity.this.authorUsernameView.setTextColor(Color.parseColor(this.colorHex));
      }
    }
  }
}



/* Location:           C:\Users\Administrator\Downloads\Convert APK to Code\dex2jar-0.0.9.15\dex2jar-0.0.9.15\classes-dex2jar.jar

 * Qualified Name:     com.m2team.xomnhiepanh.ImageActivity

 * JD-Core Version:    0.7.0.1

 */